package com.yc.SelectCourse.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.yc.SelectCourse.biz.BizException;
import com.yc.SelectCourse.util.StuUtils;
import com.yc.shopping.util.DBHelper;

public class FindSelectedCourseDao {
	
	//查看已经选择的课程
	public List<Map<String,Object>> findSelected(String sid) throws BizException{
		String sql = "select c.cid id,cname coursename,c.ccreadit creadit,t.tname teachername,c.classroom room from student stu "
				+ "inner join student_course sc on stu.sid = sc.sid "
				+ "inner join course c on sc.cid = c.cid "
				+ "inner join teacher t  on c.tid = t.tid where stu.sid = ? ";
		try {
			return DBHelper.selectListMap(sql,sid);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new BizException("业务异常,请联系管理员");
		}
	}
	
	//取消所选课程
	public void delete(String cid) throws BizException {
		String sql = "delete from student_course where sid = ? and cid = ?";
		try {
			DBHelper.update(sql, "10011001001", cid);//StuUtils.user.toString() 获取用户id
		} catch (SQLException e) {
			e.printStackTrace();
			throw new BizException("业务异常,请联系管理员",e);
		}
	}
}
